package cn.springmvc.dao;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import cn.springmvc.common.datasource.DataSourceEnum;
import cn.springmvc.common.datasource.DynamicDataSourceHolder;
import cn.springmvc.entity.News;
import cn.springmvc.repository.NewsRepository;

/**
 * @author Vincent.wang
 *
 */
@Repository
public class NewsDaoService {

    @Autowired
    protected NewsRepository newsRepository;

    public News save(News news) {
        DynamicDataSourceHolder.setDataSourceKey(DataSourceEnum.SLAVE.getKey());
        return newsRepository.save(news);
    }

    public List<News> findNews() {
        DynamicDataSourceHolder.setDataSourceKey(DataSourceEnum.SLAVE.getKey());
        return newsRepository.findNews();
    }

    public List<News> findNewsByKeywords(String keywords) {
        DynamicDataSourceHolder.setDataSourceKey(DataSourceEnum.SLAVE.getKey());
        return newsRepository.findNewsByKeywords(keywords);
    }
}
